package model;

public class Pack {
	private int posX,posY,velX,velY;
	private boolean movesHorizontally,isDead;
	Map level;

	private static final int vel = 10; 
	private static final int tamPack = 15; 
	
	// constructor
	public Pack(int x, int y, Map map){
		posX = x;
		posY = y;
		velX = 0;
		velY = 0;
		level = map;
		movesHorizontally = true;
		isDead = false;
	}
	
	// moves packman can move to target position 
	public void move(){
		if((!isDead) && level.canMove(posX, posY, posX+3*velX, posY+3*velY,movesHorizontally)){
			posX = posX+velX;
			posY = posY+velY;
			
			if(posX < -20) posX = 960;
			if(posX > 960) posX = -20;
		}
	}

	// stops movment
		public void stop() {
			this.velX = 0;
			this.velY = 0;
		}		
	
	// sets movment speed in the X axis
	public void setSpeedX(int dirX) {
		this.velX = dirX*vel;
		this.velY = 0;
		this.movesHorizontally = true;
	}	

	// sets movment speed in the X axis
	public void setSpeedY(int dirY) {
		this.velY = dirY*vel;
		this.velX = 0;
		this.movesHorizontally = false;
	}	
	
	// returns the x-position
	public int getX() {
		return posX;
	}

	// returns the y-position
	public int getY() {
		return posY;
	}	
	
	// returns true if there is a colission
	public boolean colidesWith(Ghost ghost){
		int ghostPosX = ghost.getX();
		int ghostPosY = ghost.getY();
		int ghostTam = ghost.getTam();
		
		return (Math.sqrt(Math.pow((posX-ghostPosX)/2,2) + Math.pow((posY-ghostPosY)/2,2)) < (tamPack+ghostTam)/2);
	}

	// changes status to dead
	public void die() {
		isDead = true;
	}
	
	// returns true if packman is dead
	public boolean isDead(){
		return isDead;
	}
}
